/**
 * created by 小卷毛, 2022-02-28
 * Copyright (c) 2022, 416143467@qq.com All Rights Reserved.
 * #                   *********                            #
 * #                  ************                          #
 * #                  *************                         #
 * #                 **  ***********                        #
 * #                ***  ****** *****                       #
 * #                *** *******   ****                      #
 * #               ***  ********** ****                     #
 * #              ****  *********** ****                    #
 * #            *****   ***********  *****                  #
 * #           ******   *** ********   *****                #
 * #           *****   ***   ********   ******              #
 * #          ******   ***  ***********   ******            #
 * #         ******   **** **************  ******           #
 * #        *******  ********************* *******          #
 * #        *******  ******************************         #
 * #       *******  ****** ***************** *******        #
 * #       *******  ****** ****** *********   ******        #
 * #       *******    **  ******   ******     ******        #
 * #       *******        ******    *****     *****         #
 * #        ******        *****     *****     ****          #
 * #         *****        ****      *****     ***           #
 * #          *****       ***        ***      *             #
 * #            **       ****        ****                   #
 */
package com.rzico.sbl.viewmodel

import com.lzg.extend.BaseResponse
import com.lzg.extend.jackson.JacksonConvert
import com.lzg.okrx.adapter.FlowableBody
import com.lzy.okgo.OkGo
import com.rzico.sbl.model.ManagerOrderData
import com.rzico.sbl.model.ManagerWayModel
import com.rzico.sbl.ui.report.other.ReportUrl
import com.xinnuo.common_ui.utils.applyFlowableSchedulers
import com.xinnuo.common_ui.utils.subscribeByFinally

/**
 * 描 述：报货总经理收入方式操作相关
 * 作 者：小卷毛  2022-02-28 09:19
 * 修改描述：
 * 修 改 人：
 * 修改版本：
 */
class ReportMethodViewModel : ColorViewModel() {

    /**
     * 支付方式柱状图数据
     */
    fun payRangeList(
        beginDate: String,
        endDate: String,
        onSuccess: (ManagerWayModel) -> Unit = {},
        onFinally: () -> Unit = {}
    ) = mDisposables.add(
        OkGo.get<BaseResponse<ManagerWayModel>>(ReportUrl.getBaseUrl().zWayDetail)
            .params(
                getParams(
                    "beginDate" to beginDate,
                    "endDate" to endDate
                )
            )
            .converter(object : JacksonConvert<BaseResponse<ManagerWayModel>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .map { it.data }
            .subscribeByFinally(
                event = this,
                onSuccess = onSuccess,
                onFinally = onFinally
            )
    )

    /**
     * 支付明细列表
     */
    fun payDetailList(
        page: Int,
        type: String,
        beginDate: String,
        endDate: String,
        onSuccess: (ArrayList<ManagerOrderData>) -> Unit = {},
        onFinally: () -> Unit = {}
    ) = mDisposables.add(
        OkGo.get<BaseResponse<ArrayList<ManagerOrderData>>>(ReportUrl.getBaseUrl().zWayList)
            .params(
                getParams(
                    "type" to type,
                    "beginDate" to beginDate,
                    "endDate" to endDate,
                    "pageStart" to page * 20,
                    "pageSize" to 20
                )
            )
            .converter(object : JacksonConvert<BaseResponse<ArrayList<ManagerOrderData>>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .map { it.data }
            .subscribeByFinally(
                event = this,
                onSuccess = onSuccess,
                onFinally = onFinally
            )
    )

}